<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/12/18
 * Time: 13:32
 */

namespace app\adminapiv3\validate;


use think\Validate;

class ServerDownloadValidate extends Validate
{
    protected $rule = [
        //主机ID
        'id|ID' => 'require',
        'host_id|资产ID' => 'require',
        'module|模块名称' => 'require|in:1,2|checkTime',
        'start_time|开始时间' => 'date',
        'end_time|结束时间' => 'date',
    ];



    protected $scene = [
        //创建
        'create' => ['host_id', 'module', 'start_time', 'end_time'],

        //删除
        'del' => ['id'],

    ];


    protected function checkTime($value, $rule, $data = [])
    {
        if($data['module'] == 1){
            if(empty($data['start_time'])){
                return '开始时间不能为空';
            }
            if(empty($data['end_time'])){
                return '结束时间不能为空';
            }
        }

        return true;
    }

}